/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.model;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author arnold
 */
@Entity
@Table(name = "storage_product")
public class StorageProduct extends BaseObject implements Serializable {

    private Long id;
    private Product product;
    private Integer stock;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    @Override
    public String toString() {
        return "com.click.app.model.StorageProduct[id=" + id + "]";
    }

    @Override
    public boolean equals(Object o) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(o instanceof StorageProduct)) {
            return false;
        }
        StorageProduct other = (StorageProduct) o;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**
     * @return the product
     */
    @OneToOne
    @JoinColumn(name = "id_product")
    public Product getProduct() {
        return product;
    }

    /**
     * @param product the product to set
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    public void incrementStok(Integer quantity) {
        this.stock = stock + quantity;
    }

    public void decrementStok(Integer quantity) {
        this.stock = stock - quantity;
    }
}
